/* Copyright 2017 The Apollo Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
#ifndef MODULES_MAP_HDMAP_ADAPTER_ODR_PARSER_LANE_ODR_PARSER_H_
#define MODULES_MAP_HDMAP_ADAPTER_ODR_PARSER_LANE_ODR_PARSER_H_

#include <string>
#include <vector>

#include "tinyxml2/tinyxml2.h"

#include "modules/map/hdmap/adapter/odr_parser/data_define.h"

#include "modules/map/hdmap/adapter/xml_parser/common_define.h"
#include "modules/map/hdmap/adapter/xml_parser/status.h"

namespace apollo {
namespace hdmap {
namespace adapter {

class LanesOdrParser {
 public:
  static Status Parse(std::string road_id, const tinyxml2::XMLElement& xml_node,
                                 std::vector<LaneSection*>* sections);

 private:
  static Status ParseLaneSection(std::string road_id, size_t sectionIndex,  const tinyxml2::XMLElement& xml_node,
                                 LaneSection* lanes);

  static Status ParseLane(std::string uidPrefix, const tinyxml2::XMLElement& xml_node,
                          Lane* lane);

  static Status ParseWidth(const tinyxml2::XMLElement& xml_node, Lane* lane);
  static Status ParseBorder(const tinyxml2::XMLElement& xml_node, Lane* lane);
  static Status ParseWidthAttributes(const tinyxml2::XMLElement* sub_node,
                                              LaneWidth& width);

  static Status ParseRoadMark(const tinyxml2::XMLElement& xml_node, Lane* lane);
  static Status ParseSpeed(const tinyxml2::XMLElement& xml_node, Lane* lane);

  static Status ToLaneType(const std::string& type, LaneType* pb_type);

  static Status ParseLaneLink(const tinyxml2::XMLElement& xml_node,
                            Lane* lane);
  static Status ToRoadMarkType(const std::string& type,
                                 RoadMarkType* roadmark_type);
  static Status ToRoadMarkColor(const std::string& color,
                                 RoadMarkColor& roadmark_color);
};

}  // namespace adapter
}  // namespace hdmap
}  // namespace apollo

#endif  // MODULES_MAP_HDMAP_ADAPTER_ODR_PARSER_LANE_ODR_PARSER_H_
